import { axios, pureAxios } from '@/utils/request'

const api = {
  login: '/auth/login',
  logout: '/auth/logout',
  smCode: '/code/smCode',
  imageCode: '/code/imageCode',
  userInfo: '/user/userInfo',
  permission: '/menu'
}

/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login (parameter) {
  return axios({
    url: api.login,
    method: 'post',
    data: parameter
  })
}

export function getInfo () {
  return axios({
    url: api.userInfo,
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function logout (token) {
  return axios({
    url: api.logout,
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      'token': token
    }
  })
}

export function getImagecode () {
  return pureAxios({
    url: api.imageCode,
    method: 'get',
    responseType: 'blob'
  })
}

export function getSmsCode (parameter) {
  return axios({
    url: api.sendSms,
    method: 'post',
    data: parameter
  })
}
